# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=libmowgli
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.1.3
pkgrel=4
pkgdesc="Performance and usability-oriented extensions to C (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://github.com/atheme"
license=('GPL')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs" "${MINGW_PACKAGE_PREFIX}-openssl")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
options=('staticlibs' 'strip')
source=(${_realname}-${pkgver}.tar.gz::https://github.com/atheme/${_realname}-2/archive/v${pkgver}.tar.gz
        libmowgli-mingw-fix.patch)
sha256sums=('b7faab2fb9f46366a52b51443054a2ed4ecdd04774c65754bf807c5e9bdda477'
            '2a73bcc8df44197e95ad7add3b2845a21c033819bff361f5d8ce33e6561bba3f')

prepare() {
  cd ${srcdir}/${_realname}-2-${pkgver}

  # inet_pton & inet_ntop are already defined in ws2tcpip.h
  patch -p1 -i ${srcdir}/libmowgli-mingw-fix.patch

  cd ${srcdir}
  [[ -d ${srcdir}/build-${MSYSTEM} ]] && rm -rf ${srcdir}/build-${MSYSTEM}
  cp -rf ${_realname}-2-${pkgver} build-${MSYSTEM}
}

build() {
  cd ${srcdir}/build-${MSYSTEM}
  ./configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --enable-shared \
    --enable-static \
    --with-openssl

  make
}

package() {
  cd ${srcdir}/build-${MSYSTEM}
  make DESTDIR="${pkgdir}" install

  install -Dm644 COPYING "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
}
